import type { InjectionKey } from 'vue'
import type { Store } from 'vuex'
import type { IRootGetters } from './getters'
import type { IModuleState } from './module'

import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import getters from './getters'
import modules from './module'

export const injectKey: InjectionKey<Store<IRootState>> = Symbol()

export type IRootState = IModuleState
declare class RootStore extends Store<IRootState> {
  readonly getters: IRootGetters
}

export default createStore({
  getters,
  modules: modules,
  plugins: [createPersistedState({
    storage: import.meta.env.DEV ? sessionStorage : localStorage
  })]
}) as RootStore